package com.affaris.service.impl;

import com.affaris.controller.dto.UsersPassDTO;
import com.affaris.entity.Users;
import com.affaris.mapper.UsersMapper;
import com.affaris.service.UsersService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lucas
 * @since 2023-05-15
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

    @Resource
    private UsersMapper usersMapper;
    @Override
    public Boolean updatePassword(UsersPassDTO usersPassDTO) {
        // 判断旧密码是否正确
        Users user = usersMapper.selectOne(new QueryWrapper<Users>().eq("student_id", usersPassDTO.getStudentId()));
        if (!user.getPassword().equals(usersPassDTO.getPassword())) {
            return false;
        }
        // 更新密码
        user.setPassword(usersPassDTO.getNewPassword());
        return usersMapper.updateById(user) > 0;

//        return usersMapper.updatePassword(usersPassDTO);
    }
}
